import React, { Component,createRef } from 'react'

export default class App extends Component {
    // 1. 创建ref对象
    inputRef = createRef(true)
    render() {
        console.log('init ref: ', createRef());// {current:null}
        return (
            <div>
                <h3>App</h3>
                <p><input type="text" name="" ref={this.inputRef} /></p>
                <p><button onClick={()=>{
                    console.log('ref: ', this.inputRef); //{current: input}
                    console.log('dom:', this.inputRef.current);// input  dom元素
                    console.log('value: ', this.inputRef.current.value); // input文本框的值

                }}>获取ref对象</button></p>
            </div>
        )
    }
}
